package com.kid.keep.pattern;


import com.kid.keep.enums.BizExceptionEnum;
import com.kid.keep.enums.ReportGradeEnum;
import com.kid.keep.exception.BizException;
import com.kid.keep.po.CheckItemStandard;
import lombok.Data;

import java.util.Objects;

/**
 * @Description 报告得分等级
 * @Author JOHN
 * @Create 2020-01-03
 * @Since 1.0.0
 */
@Data
public abstract class AbstractReportGradePattern {

    private AbstractReportGradePattern next;

    /**
     * 执行
     *
     * @param scope
     * @return
     */
    public abstract CheckItemStandard execute(Integer scope);


    protected CheckItemStandard getGrade(CheckItemStandard checkItemStandard, Integer scope) {
        if (Objects.isNull(checkItemStandard.getMinValue()) && scope >= checkItemStandard.getMaxValue()) {
            return checkItemStandard;
        }

        if (Objects.isNull(checkItemStandard.getMaxValue()) && scope <= checkItemStandard.getMinValue()) {
            return checkItemStandard;
        }

        if (  Objects.nonNull(checkItemStandard.getMaxValue())&&Objects.nonNull(checkItemStandard.getMinValue()) && scope <= checkItemStandard.getMaxValue() && scope >= checkItemStandard.getMinValue()) {
            return checkItemStandard;
        }
        return null;
    }

    protected CheckItemStandard execute(CheckItemStandard checkItemStandard,Integer scope){
        if (Objects.nonNull(checkItemStandard)) {
            return checkItemStandard;
        }
        if (Objects.nonNull(getNext())) {
            return getNext().execute(scope);
        }
        throw BizException.getInstance(BizExceptionEnum.GRADE_NOT_EXISTS);
    }
}
